<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of createsubmission
 *
 * @author srkrishnan
 */

/**

 * @property CI_Loader $load

 * @property CI_Form_validation $form_validation

 * @property CI_Input $input

 * @property CI_Email $email

 * @property CI_DB_active_record $db

 * @property CI_DB_forge $dbforge
 * 
 * @property problem $problem 
 * 
 * @property Solution $solution

 */
class Createsubmission extends CI_Controller {

    private $userid = 'anantha89', $password = 'myideone';

    function Createsubmission() {
        parent::__construct();
        $this->load->model('solution');
    }

    function index() {

        $code = '';

        $languageid = '';

        $input = '';

        $run = true;

        $private = true;


        $code = trim($this->input->post('code'));
        $input = trim($this->input->post('input'));
        $languageid = trim($this->input->post('languageid'));
        $logic = trim($this->input->post('logic'));

        $this->solution->insertsolution($code, $languageid, $logic);

        try {
            //create new SoapClient
            $client = new SoapClient("http://ideone.com/api/1/service.wsdl");

            //create new submission
            $result = $client->createSubmission($this->userid, $this->password, $code, $languageid, $input, $run, $private);

            $jsonresult = array(
                'result' => $result
            );
        } catch (Exception $e) {
            $jsonresult = array(
                'error' => $e
            );
        }
        $jsonresult = json_encode($jsonresult);
        echo $jsonresult;
    }

    
}

?>
